Merge pull request #137 from viettaml/master
authorRobert Lipe <robertlipe@users.noreply.github.com>
Sat, 7 Jul 2018 05:37:36 +0000 (00:37 -0500)
committerGitHub <noreply@github.com>
Sat, 7 Jul 2018 05:37:36 +0000 (00:37 -0500)
Fix redundant file rename on Windows

1  2 
kml.cc

diff --cc kml.cc
index e59ba51e82ba9cdc0f558984f2005b0b99f745d8,4b75a8b6f3a266ff7a5ecd03196064e3ba2a72f4..32d467fbec76e1f037d85aa4b9c0871e2143c8db
--- 1/kml.cc
--- 2/kml.cc
+++ b/kml.cc
@@@ -580,17 -534,16 +580,16 @@@ kml_wr_deinit(
  {
    writer->writeEndDocument();
    delete writer;
 -  writer = NULL;
 +  writer = nullptr;
    oqfile->close();
    delete oqfile;
 -  oqfile = NULL;
 +  oqfile = nullptr;
  
    if (!posnfilenametmp.isEmpty()) {
- #if __WIN32__
-     MoveFileExW((const wchar_t*) posnfilenametmp.utf16(),
-                 (const wchar_t*) posnfilename.utf16(),
-                 MOVEFILE_REPLACE_EXISTING);
- #endif
+     // QFile::rename() can't replace an existing file, so do a QFile::remove()
+     // first (which can fail silently if posnfilename doesn't exist). A race
+     // condition can theoretically still cause rename to fail... oh well.
+     QFile::remove(posnfilename);
      QFile::rename(posnfilenametmp, posnfilename);
    }
  }